package com.platform.user.service;

import com.platform.bean.JsonResult;
import com.platform.user.dao.TbTestDao;
import com.platform.utils.Base64Utils;
import com.platform.utils.UploadFileToRemoteUtils;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@Service
public class TestService {

    @Resource
    private TbTestDao tbTestDao;

//    public void insert(String content) {
//        try {
//            String text = processRichText(content);
//            System.out.println(text);
//
//        } catch (IOException e) {
//            throw new RuntimeException(e);
//        }
//        // tbTestDao.insert(content);
//    }

    public String generateFileUrl(String fileName) {
        // 在实际应用中，返回文件的访问 URL
        return "http://localhost:8080/images/" + fileName;
    }

    private static final String IMAGE_STORAGE_DIR = "path/to/your/image/storage"; // 修改为你的存储路径


    public String saveBase64Image(String base64Image, String fileType) throws IOException {
        String fileName = UUID.randomUUID().toString() + "." + fileType;
        File file = new File(String.valueOf(Paths.get(IMAGE_STORAGE_DIR, fileName).toFile()));

        // 解码 Base64 并写入文件
        byte[] imageBytes = java.util.Base64.getDecoder().decode(base64Image);
        try (FileOutputStream fos = new FileOutputStream(file)) {
            fos.write(imageBytes);
        }

        return generateFileUrl(fileName);
    }
}
